package com.yequan.designpattern.factory.simplefactory.reflect;

import com.yequan.designpattern.factory.IProduct1;

public class ReflectFactory {

    /**
     * 只适用于无参构造函数，也就是只能用于简单的对象创建，而不适用多参数对象的创建
     *
     * @param clz
     * @param <T>
     * @return
     */
    public static <T extends IProduct1> T createProduct(Class<T> clz) {
        T result = null;
        try {
            result = (T) Class.forName(clz.getName()).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public static Object CreateProduct(String className) {
        Object instance = null;
        try {
            instance = Class.forName(className).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return instance;
    }

}
